const API_TARGET = 'http://10.168.1.65:31777' //测试环境
// const API_TARGET = 'http://192.168.15.56:31066' //开发环境

const FORECAST_API_TARGET = 'http://10.168.1.65:32431'
//k8s日志代理
// const K8S_TARGET = 'http://192.168.15.56:32054' //开发环境
const K8S_TARGET = 'http://10.168.1.65:32464' //测试环境

const WS_TARGET = 'ws://10.168.1.65:30865'

export default {
  port: 8410,
  cors: true, // 允许跨域
  host: '0.0.0.0',
  proxy: {
    '^/api/': {
      target: API_TARGET,
      changeOrigin: true,
      rewrite: (path: string) => path.replace(/^\/api/, '')
    },
    '^/socket/': {
      target: WS_TARGET,
      changeOrigin: true,
      ws: true,
      rewrite: (path: string) => path.replace(/^\/socket/, '')
    },
    '^/forecast/': {
      target: FORECAST_API_TARGET,
      changeOrigin: true
    },
    '^/minio/': {
      target: 'http://10.168.1.65:31673',
      changeOrigin: true,
      rewrite: (path: string) => path.replace(/^\/minio/, '')
    },
    '^/k8s/': {
      target: K8S_TARGET,
      changeOrigin: true,
      rewrite: (path: string) => path.replace(/^\/k8s/, '')
    },
    '^/p-img1/(\\d)x(\\d)/(.*)': {
      target: 'http://192.168.15.56:31066',
      changeOrigin: true,
      rewrite: path => {
        // 将路径重写为对应的目标路径
        const [, w, h, filePath] = path.match(/^\/p-img\/(\d+)x(\d+)\/(.*)$/)
        const resolution = `${w}x${h}`
        // filePath里的问号替换成&
        const newFilePath = filePath.replace(/\?/g, '&')
        console.log(111)

        console.log(
          `http://171.217.69.51:31777/cloud/thirdparty/v1/generate-thumbnail/${w}x${h}?X-Amz-URL=http://171.217.69.51:31673/${newFilePath}`
        )

        return `http://171.217.69.51:31777/cloud/thirdparty/v1/generate-thumbnail/${w}x${h}?X-Amz-URL=http://171.217.69.51:31673`
      }
    },
    // 代理到测试环境
    '/p-img/': {
      target: 'http://10.168.1.65:32431',
      changeOrigin: true
    }
  }
}
